let db = require('../db/index')

exports.get = (req,res) =>{//通过姓名查询数据
    var sql = "select * from testcase where cname like '%' ?"
    db.query(sql,[req.query.cname],(err,data)=>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })
}

exports.del = (req,res) =>{//通过姓名删除数据
    var sql = 'delete from testcase where cname = ?'
    db.query(sql,[req.query.cname],(err,data) =>{
        if(err){
            return res.send('错误：' +err.message)
        }
        res.send(data)
    })

}

exports.add = (req,res)=>{
    var sql = 'insert into testcase (cname,method,type,port,data,id) values (?,?,?,?,?,?)'
    db.query(sql, [req.query.cname, req.query.method, req.query.type, req.query.port, req.query.data, req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}

exports.update = (req,res)=>{
    var sql = 'update testcase set cname = ?, method = ?,type = ?,port = ?,data = ? where id = ?'
    db.query(sql, [req.query.cname,req.query.method,req.query.type,req.query.port,req.query.data,req.query.id],(err,data)=>{
        if(err){
            return res.send('错误：'+err.message)
        }
        res.send(data)
    })
}